package com.houweishi.module.clockbinding.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.clockbinding.domain.BizClockingBinding;
import com.houweishi.module.clockbinding.service.IBizClockingBindingService;
import com.houweishi.module.clockedtype.service.IBizClockedTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 员工与打卡类型绑定Controller
 * 
 * @author houweishi
 * @date 2023-03-02
 */
@RestController
@RequestMapping("/module/clockbinding")
public class BizClockingBindingController extends BaseController
{
    @Autowired
    private IBizClockingBindingService bizClockingBindingService;

    @Resource
    private IBizClockedTypeService bizClockedTypeService;


    /**
     * 查询员工与打卡类型绑定列表(同时拿到员工对应的打卡时间区间列表）
     */
//    @PreAuthorize("@ss.hasPermi('module:clockbinding:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizClockingBinding bizClockingBinding)
    {
        startPage();
        List<BizClockingBinding> list = bizClockingBindingService.selectBizClockingBindingList(bizClockingBinding);
        return getDataTable(list);
    }

    /**
     * 导出员工与打卡类型绑定列表
     */
    @PreAuthorize("@ss.hasPermi('module:clockbinding:export')")
    @Log(title = "员工与打卡类型绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizClockingBinding bizClockingBinding)
    {
        List<BizClockingBinding> list = bizClockingBindingService.selectBizClockingBindingList(bizClockingBinding);
        ExcelUtil<BizClockingBinding> util = new ExcelUtil<BizClockingBinding>(BizClockingBinding.class);
        util.exportExcel(response, list, "员工与打卡类型绑定数据");
    }

    /**
     * 获取员工与打卡类型绑定详细信息
     */
//    @PreAuthorize("@ss.hasPermi('module:clockbinding:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizClockingBindingService.selectBizClockingBindingById(id));
    }

    /**
     * 新增员工与打卡类型绑定
     */
    @PreAuthorize("@ss.hasPermi('module:clockbinding:add')")
    @Log(title = "员工与打卡类型绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizClockingBinding bizClockingBinding)
    {
        return bizClockingBindingService.insertBizClockingBinding(bizClockingBinding);
    }

    /**
     * 修改员工与打卡类型绑定
     */
    @PreAuthorize("@ss.hasPermi('module:clockbinding:edit')")
    @Log(title = "员工与打卡类型绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizClockingBinding bizClockingBinding)
    {
        return toAjax(bizClockingBindingService.updateBizClockingBinding(bizClockingBinding));
    }

    /**
     * 删除员工与打卡类型绑定
     */
    @PreAuthorize("@ss.hasPermi('module:clockbinding:remove')")
    @Log(title = "员工与打卡类型绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizClockingBindingService.deleteBizClockingBindingByIds(ids));
    }

    @GetMapping("/info/{staffId}")
    public AjaxResult getStaffClockInfo(@PathVariable Long staffId){
        return bizClockingBindingService.getStaffClockInfo(staffId);
    }
}
